@import 'mixins/form';
@import 'mixins/selectbox';

$select-option-height: 32px;

@include b(select) {
  @include component-in-form('#{&}') {
    width: 100%;
  }

  @include component-selectbox;

  @include when(disabled) {
    @include e(multiple-tag) {
      color: var(--#{$rd-prefix}color-disabled);
    }
    @include e(multiple-count) {
      color: var(--#{$rd-prefix}color-disabled);
    }
  }

  @include e(multiple-tag) {
    & + & {
      margin-left: 8px;
    }
  }

  @include e(close) {
    margin: 0 0 0 4px;
    color: var(--#{$rd-prefix}color-icon-decorator);
    transition: color var(--#{$rd-prefix}animation-duration-base) linear;

    &:hover,
    &:focus {
      color: var(--#{$rd-prefix}color-primary-lighter);
    }

    &:active {
      color: var(--#{$rd-prefix}color-primary-darker);
    }
  }

  @include e(popup) {
    position: fixed;
    background-color: var(--#{$rd-prefix}background-color);
    border-radius: var(--#{$rd-prefix}border-radius);
    box-shadow: var(--#{$rd-prefix}shadow-popup);
  }

  @include e(list) {
    position: relative;
    max-height: 264px;
    padding: 4px 0;
    margin: 0;
    overflow: hidden auto;
    list-style: none;
  }

  @include e(option) {
    @include polyfill-column-gap(8px);

    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: $select-option-height;
    padding: 0 12px;
    cursor: pointer;
    transition: background-color var(--#{$rd-prefix}animation-duration-base) linear;

    &:not(.is-selected):hover {
      background-color: var(--#{$rd-prefix}background-color-hover);
    }

    @include when(disabled) {
      color: var(--#{$rd-prefix}color-disabled);
      pointer-events: none;
    }

    @include when(selected) {
      background-color: var(--#{$rd-prefix}background-color-primary);
    }
  }

  @include e(option-content) {
    @include utils-ellipsis;

    flex: 1 0 0;
  }

  @include e(option-group) {
    padding: 0;
    margin: 0;
    list-style: none;
  }

  @include e(option-group-label) {
    display: flex;
    align-items: center;
    height: $select-option-height;
    padding: 0 12px;
    font-size: 0.9em;
    color: var(--#{$rd-prefix}text-color-sub);
  }

  @include e(empty) {
    display: flex;
    align-items: center;
    height: $select-option-height;
    padding: 0 12px;
    color: var(--#{$rd-prefix}color-disabled);
  }

  @include e(loading) {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    color: var(--#{$rd-prefix}color-primary);
    background-color: rgb(var(--#{$rd-prefix}background-color-rgb) / 80%);

    @include m(empty) {
      justify-content: flex-start;
      background-color: var(--#{$rd-prefix}background-color);
    }
  }
}
